dojo.require('dojo.html.util');

// Make sure document.getElementById() works
if(document.all && !document.getElementById) {
    document.getElementById = function(id) {
         return document.all[id];
    }
}

function positionElement(e, xOffset, yOffset, elm)
{
	var xPos = 0;
	var yPos = 0;

	if (!e) var e = window.event;

	if (e.pageX || e.pageY)
	{
		xPos = e.pageX;
		yPos = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		var scrollTop;
		var scrollLeft;

		if(document.compatMode && document.compatMode == 'CSS1Compat')
		{
			scrollTop = document.body.parentNode.scrollTop;
			scrollLeft = document.body.parentNode.scrollLeft;
		}
		else
		{
			scrollTop = document.body.scrollTop;
			scrollLeft = document.body.scrollLeft;
		}

		xPos = e.clientX + scrollLeft;
		yPos = e.clientY + scrollTop;
	}

	xPos += xOffset;
	yPos += yOffset;

	dojo.html.placeOnScreen(elm, xPos, yPos, 0, true);
}

/**
 * Return the left position of the given element.
 */
function getLeftPosition(elem) {
    var currentLeft = 0;
    if (elem.offsetParent) {
        while (elem.offsetParent) {
            currentLeft += elem.offsetLeft
            elem = elem.offsetParent;
        }
    } else if (elem.x) {
        currentLeft += elem.x;
    }
    return currentLeft;
}

/**
 * Return the top position of the given element.
 */
function getTopPosition(elem) {
    var currentTop = 0;
    if (elem.offsetParent) {
        while (elem.offsetParent) {
            currentTop += elem.offsetTop
            elem = elem.offsetParent;
        }
    } else if (elem.y) {
        currentTop += elem.y;
    }
	return currentTop;
}

function orderThankYouPagePrint()
        {

        if (window.print) {
                window.print();
                }
        else
                alert("Sorry, your browser does not support this feature.\nPlease choose print from the File menu.");
        }

/* End Sirsh */

function addEventToObject(obj, evt, func)
	{
	var oldhandler = obj[evt];
	if(typeof obj[evt] != 'function'){obj[evt] = func;}
	else{obj[evt] = function(){oldhandler();func();}}
	}
function preloadImages(imageArray)
	{
	var tempImages = new Array();
	for(var i=0;i<imageArray.length;i++){tempImages[i] = new Image();tempImages[i].src = imageArray[i];}
	return true;
	}
function insertAfter(newElement,existingElement)
	{
	var parentElement = existingElement.parentNode;
	if(parentElement.lastChild == existingElement){return parentElement.appendChild(newElement);}
	else{return parentElement.insertBefore(newElement,existingElement.nextSibling);}
	}
function arrayImageSwap(imageId,arrayName,arrayPos,delay,loop)
	{
	document.getElementById(imageId).src = arrayName[arrayPos];
	if(arrayPos+1<arrayName.length){setTimeout(function(){arrayImageSwap(imageId,arrayName,arrayPos+1,delay,loop)},delay);}
	else if(loop == 1){setTimeout(function(){arrayImageSwap(imageId,arrayName,0,delay,loop)},delay);}
	return true;
	}
function singleImageSwap(oldImageId,newImageSrc)
	{
	document.getElementById(oldImageId).src = newImageSrc;
	return true;
	}
function getElementsByClassName(parentNode,node,classname)
	{
	var a = [];
	var re = new RegExp('(^| )'+classname+'( |$)');
	var els = parentNode.getElementsByTagName(node);
	for(var i=0,j=els.length; i<j; i++)
    if(re.test(els[i].className)) {
        (a.push) ? a.push(els[i]) : a[a.length] = els[i];
    }
	return a;
	}
function stopDefaultAction(ev)
	{
	if (!ev) ev = window.event;
	(ev.stopPropagation) ? ev.stopPropagation() : ev.cancelBubble = true;
	(ev.preventDefault) ? ev.preventDefault() : ev.returnValue = false;
	return false;
	}